<template>

	<view>
		<u-cell-group>
		<uni-card :title="name" :sub-title="userid" :extra="job" thumbnail="https://web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png">
			<text></text>
		</uni-card>
		</u-cell-group>
		<u-divider text="分割线" :dot="true"></u-divider>
	<!-- 	<u-cell-group>
		    <u-cell
		        :title="name"
		        :value="job"
		        :label="userid"
				:border="true"
				customStyle="margin:20px;"
		        center
		    ></u-cell>
		</u-cell-group> -->

		<u-grid :border="false" @click="click" col="3">
			<u-grid-item v-for="(listItem,listIndex) in list" :key="listIndex">
				<u-icon :customStyle="{paddingTop:20+'rpx'}" :name="listItem.name" :size="22"></u-icon>
				<text class="grid-text">{{listItem.title}}</text>
			</u-grid-item>
		</u-grid>
	
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import store from '@/store/index.js'	
	export default {
		data() {
			return {
				list: [],
				list1: [{
						name: 'scan',
						title: '报修',
						url: 'repair',
					},
					{
						name: 'more-circle',
						title: '我报修的',
						url: 'rapairList1',
					},
				],
				list2: [
					{
						name: 'setting',
						title: '维护',
						url: 'safeguard',
					},
					{
						name: 'setting-fill',
						title: '维修',
						url: 'rapairFinish',
					},
					{
						name: 'list',
						title: '我维修的',
						url: 'rapairList2',
					},
					{
						name: 'search',
						title: '设备维修',
						url: 'waixiuList',
					},
					{
						name: 'list-dot',
						title: '我维护的',
						url: 'safelist',
					},
				],
				list3: [{
						name: 'scan',
						title: '报修',
						url: 'repair',
					},
					{
						name: 'more-circle',
						title: '我报修的',
						url: 'rapairList1',
					},
					{
						name: 'more-circle',
						title: '发布任务',
						url: 'waixiu',
					},
					{
						name: 'file-text',
						title: '我发布的',
						url: 'waixiuList',
					},
				],
				userid: '',
				name: '',
				group_id: '',
				job:'',
			}
		},
		methods: {
			onLoad(){
				if (typeof(uni.getStorageSync("userinfo.userid")) == "undefined" || uni.getStorageSync("userinfo.userid") == '' || uni.getStorageSync("userinfo.userid") == null) {
					uni.navigateTo({
						url: "/pages/index/index"
					});
				}else{
					store.commit('login');
				};
				if (typeof(uni.getStorageSync("userinfo.nickname")) == "undefined" || uni.getStorageSync("userinfo.nickname") == '' || uni.getStorageSync("userinfo.nickname") == null) {
					uni.navigateTo({
						url: "/pages/index/index"
					});
				}else{
					store.commit('login');
				};
				if (typeof(uni.getStorageSync("userinfo.group_id")) == "undefined" || uni.getStorageSync("userinfo.group_id") == '' || uni.getStorageSync("userinfo.group_id") == null) {
					uni.navigateTo({
						url: "/pages/index/index"
					});
				}else{
					store.commit('login');
				}
				this.userid=store.state.userinfo.userid;
				this.name=store.state.userinfo.nickname;
				this.group_id=store.state.userinfo.group_id;
				uni.request({
					url: 'https://wdzbx.zsbike.com.cn:10787/api.v1/home',
					method: 'GET',
					data: {
						userid: this.userid,
						group_id:this.group_id,
					},
					header: {
						'custom-header': 'hello' //自定义请求头信息
					},
					success: (res) => {
						if(res.data.Status==600){
							uni.navigateTo({
								url: "/pages/index/index"
							});
						}else{
							console.log(2)
						}
					}
				});
				console.log(this.group_id);
				if(this.group_id==2){
					this.list=this.list2;
					this.job="维修技工";
				}else if(this.group_id==1){
					this.list=this.list1;
					this.job="报修人"
				}else{
					this.list=this.list3;
					this.job="质过检"
				}
				console.log(this.list);
			},
			click(n) {
				if (this.list[n].url == 'safeguard') {
					uni.scanCode({
						success: function(res) {
							var url = res.result;
							var params = res.result.split('?');
							uni.navigateTo({
								url: '/pages/work/take?' + params[1]
							});
						}
					});
				}else if(this.list[n].url == 'repair'){
					uni.scanCode({
						success: function(res) {
							var url = res.result;
							var params = res.result.split('?');
							uni.navigateTo({
								url: '/pages/work/repair?' + params[1]
							});
						}
					});
				}else if(this.list[n].url == 'refer'){
					uni.navigateTo({
						url: '/pages/work/repairList'
					});
				}else if(this.list[n].url == 'rapairList2'){
					uni.navigateTo({
						url: '/pages/work/repairList?all=presons'
					});
				}else if(this.list[n].url == 'safelist'){
					uni.navigateTo({
						url: '/pages/work/safeList'
					});
				}else if(this.list[n].url == 'rapairList1'){
					uni.navigateTo({
						url: '/pages/work/repairList?all=presons'
					});
				}else if(this.list[n].url == 'rapairFinish'){
					uni.navigateTo({
						url: '/pages/work/repairList?all=all'
					});
				}else if(this.list[n].url == 'waixiu'){
					uni.navigateTo({
						url: '/pages/work/waixiu'
					});
				}else if(this.list[n].url == 'waixiuList'){
					uni.navigateTo({
						url: '/pages/work/waixiuList'
					});
				}
			}
		}
	}
</script>

<style lang="scss">
	.grid-text {
		font-size: 14px;
		color: #909399;
		padding: 10rpx 0 20rpx 0rpx;
		/* #ifndef APP-PLUS */
		box-sizing: border-box;
		/* #endif */
	}
</style>